package com.homson.servicedomain.processor;

import com.homson.coreservice.servicecommon.co.AccountDebitCO;
import com.homson.coreservice.servicecommon.enumeration.TransTypeEnum;
import com.homson.servicedomain.domain.account.AccountDebitCommand;
import com.homson.servicedomain.message.domain.model.TransactionAddedEvent;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import static com.homson.coreservice.servicecommon.enumeration.TransTypeEnum.DEBIT;


/**
 * @author: homson_leo
 * @contact: hey_超级巨星（Homson_Leo）- 刘泓岑 1196816884@qq.com
 * @time: 2025/11/1 7:45 PM
 **/
@Component
public class DebitEventProcessor extends AbstractTransEventProcessor {
    
    @Resource
    private AccountDebitCommand accountDebitCommand;
    
    @Override
    public void process(Long accountId, TransactionAddedEvent event) {
        AccountDebitCO accountDebitCO = new AccountDebitCO();
        accountDebitCO.setAccountId(event.getAccountId());
        accountDebitCO.setAmount(event.getAmount());
        accountDebitCO.setAccountType(event.getAccountType());
        accountDebitCommand.subTractAccountBalance(accountId,accountDebitCO);
    }
    
    @Override
    public TransTypeEnum getTransType() {
        return DEBIT;
    }
}
